package com.leetcode.deal;

import com.leetcode.deal.support.ListNode;

/**
 * @Author: WuPeng
 * @Date: 2022/4/2 5:10 下午
 *
 * 翻转链表，双指针解法
 *
 */
public class ReverseLinked_206 {

    public static ListNode reverseLinkedList(ListNode head){
        ListNode prev = null;
        ListNode curr = head;
        ListNode temp = null;

        while(curr != null){
            temp = curr.next;
            curr.next = prev;
            prev = curr;
            curr = temp;
        }

        return prev;
    }

    public static void main(String[] args) {
        ListNode head = ListNode.getLinkedList(10);
        ListNode.printLink(head);
        ListNode newHead = reverseLinkedList(head);
        ListNode.printLink(newHead);
    }


}
